package jmine.tec.subscription.impl;

import jmine.tec.subscription.Publisher;
import jmine.tec.subscription.Subscription;
import jmine.tec.subscription.SubscriptionSet;
import jmine.tec.subscription.SubscriptionSettings;

/**
 * Implementacao trivial de {@link Subscription}. Mantem todo o estado em variaveis.
 * 
 * @author takeshi
 */
public class SubscriptionImpl implements Subscription {

    private final SubscriptionSet containingSet;

    private final SubscriptionSettings settings;

    private final Publisher<?> publisher;

    private final long token;

    private long version;

    /**
     * C'tor
     * 
     * @param containingSet o {@link SubscriptionSet}
     * @param settings o {@link SubscriptionSettings}
     * @param publisher o {@link Publisher}
     * @param token the token
     */
    public SubscriptionImpl(SubscriptionSet containingSet, SubscriptionSettings settings, Publisher<?> publisher, long token) {
        super();
        this.containingSet = containingSet;
        this.settings = settings;
        this.publisher = publisher;
        this.token = token;
    }

    /**
     * @return the containingSet
     */
    public SubscriptionSet getContainingSet() {
        return this.containingSet;
    }

    /**
     * @return the settings
     */
    public SubscriptionSettings getSettings() {
        return this.settings;
    }

    /**
     * @return the publisher
     */
    public Publisher<?> getPublisher() {
        return this.publisher;
    }

    /**
     * {@inheritDoc}
     */
    public long getSubscriptionToken() {
        return this.token;
    }

    /**
     */
    public void incrementVersion() {
        this.version++;
    }

    /**
     * @return long
     */
    public long getVersion() {
        return this.version;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "" + this.token;
    }

}
